<?php
header("content-type:text/html;charset=utf-8");
include "../public/config/config.php";
include "../public/include/funcs.php";

$id = $_GET['id'];
//$id = 60014;
$link=conn($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname,$cfg_dbchar);

$award = [
	"0",
	"169元陶瓷养生锅",
	0,
	"39元毛绒玩具",
	"20M流量",
	0,
	"39元毛绒玩具",
	"20M流量",
	0
];

$num = mt_rand(1, 8);
$add_arr['u_id'] = $id;
$add_arr['at_id'] = 1;
$add_arr['award'] = $award[$num];
$add_arr['ma'] = mt_rand(1000, 9999).mt_rand(1000, 9999);
$add_arr['int_time'] = time();

$time = date("Y-m-d");
$time_arr = explode("-", $time);
$y = $time_arr[0];
$m = $time_arr[1];

if($award[$num]){
	//开启事务，必须是innoDB
	mysqli_query($link, "start transaction;");
	$re = add($link, "award", $add_arr);
	
	$sql = "update awa_sum set sum_b=(sum_b+1) where u_id=$id and y=$y and m=$m";
	$re2 = mysqli_query($link,$sql);
	
	if($re && $re2){
		mysqli_query($link, "commit;");
		echo $num;
	}else{
		mysqli_query($link, "rollback;");
		echo 999;
	}
}else{
	$sql = "update awa_sum set sum_b=(sum_b+1) where u_id=$id and y=$y and m=$m";
	$re3 = mysqli_query($link,$sql);
	if($re3){
		echo $num;
	}else{
		echo 999;
	}
}









?>